package com.itheima.test;

import com.itheima.mentalarithmeticpracticesystem.AddTest;
import com.itheima.mentalarithmeticpracticesystem.DivideTest;
import com.itheima.mentalarithmeticpracticesystem.MultiplyTest;
import com.itheima.mentalarithmeticpracticesystem.SubtractTest;

import java.util.ArrayList;
import java.util.Scanner;

public class Ts {
    public static void addTest(Scanner scanner, ArrayList<MathTest> mathTests) {
        String ra = "Y";
        while (true) {
            System.out.println("是否继续添加题目，是请按Y，否则任意输入");
            ra = scanner.next();
            if (ra.equals("Y")) {
                //-----------------
                System.out.println("请选择需要添加的题型：");
                System.out.println("1:加法题\n" + "2:减法题\n" + "3:乘法题\n" + "4:除法题");
                int num = scanner.nextInt();
                switch (num) {
                    case 1:
                    String nums= canNum(num);
                        AddTest addTest = new AddTest((int )nums.charAt(0), (int)nums.charAt(1));
                        mathTests.add(addTest);
                        System.out.println("题目：" + addTest.getQuestion() + "  添加成功！");
                        break;
                    case 2:
                        String num2= canNum(num);
                        SubtractTest subtractTest = new SubtractTest((int )num2.charAt(0), (int)num2.charAt(1));
                        mathTests.add(subtractTest);
                        System.out.println("题目：" + subtractTest.getQuestion() + "  添加成功！");
                        break;
                    case 3:
                        String num3= canNum(num);
                        MultiplyTest multiplyTest = new MultiplyTest((int )num3.charAt(0), (int)num3.charAt(1));
                        mathTests.add(multiplyTest);
                        System.out.println("题目：" + multiplyTest.getQuestion() + "  添加成功！");
                        break;
                    case 4:
                        String num4= canNum(num);
                        DivideTest divideTest = new DivideTest((int )num4.charAt(0), (int)num4.charAt(1));
                        mathTests.add(divideTest);
                        System.out.println("题目：" + divideTest.getQuestion() + "  添加成功！");
                        break;
                    default:
                        System.out.println("请输入有效的功能码");
                        break;
                }
                //------------------
            } else {
                System.out.println("是否继续添加题目，是请按Y，否则任意输入");
                ra = scanner.next();

                if (!ra.equals("Y")) {
                    return;
                }
            }

        }//while


    }


    public static String canNum(int num){
        Scanner scanner=new Scanner(System.in);


        int nums = num;
        String world="加";
        if (nums==2){
            world="减";
        }else if (nums==3){
            world="乘";
        }else if (nums==4){
            world="除";
        }else {
            world=world;
        }

        System.out.println("请输入"+world+"数");
        String x = scanner.next();
        System.out.println("请输入被"+world+"数");
        String y = scanner.next();


        return x+y;
    }

}
